package data_structure.digital_curation;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 914. 卡牌分组
 * https://leetcode-cn.com/problems/x-of-a-kind-in-a-deck-of-cards/
 */
public class 卡牌分组 {
    public static void main(String[] args) {
        hasGroupsSizeX(new int[]{2 , 2 ,2 ,2  ,3 ,3});
    }
    public static boolean hasGroupsSizeX(int[] deck) {
        Arrays.sort(deck);
        Map<Integer , Integer> map = new HashMap<>();
        for (int i = 0 ; i < deck.length ; i++){
            if (map.containsKey(deck[i])){
                map.put(deck[i] , (map.get(deck[i]) + 1));
            }else {
                map.put(deck[i] , 1);
            }
        }
        int n = map.get(deck[0]);
        System.out.println(n);
        for (Map.Entry<Integer , Integer> entry : map.entrySet()){
            System.out.println(entry.getValue());
            if (entry.getValue() != n || entry.getValue() < 2){
                n = gcd(n , entry.getValue());
                if (n < 2){
                    return false;
                }
            }
        }
        return true;
    }
    public static int gcd(int a , int b){
        if (b == 0){
            return a;
        }
        return gcd(b , a % b);
    }
}
